import prettier from 'prettier'
import glob from 'glob'
import path from 'path'
import fs from 'fs'

glob.sync('**/*', { cwd: path.resolve(__dirname, '../demo/java-demo'), nodir: true }).forEach((file) => {
  const filepath = path.resolve(__dirname, '../demo/java-demo', file)
  const content = fs.readFileSync(filepath, 'utf-8')
  const result = prettier.format(content, {
    parser: file.endsWith('java') ? 'java' : file.endsWith('xml') ? 'html' : file.endsWith('yml') ? 'yaml' : 'babel',
    htmlWhitespaceSensitivity: 'ignore',
    plugins: ['prettier-plugin-java'],
  })
  fs.writeFileSync(filepath, result, 'utf-8')
})
